home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / game / shoot / athrust.lha / AmigaThrust / helpers / reverse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-05  |  768 b   |  50 lines

  1.  
  2. /* Written by Peter Ekberg, peda@lysator.liu.se */
  3.  
  4. #ifdef HAVE_CONFIG_H
  5. #include "../src/config.h"
  6. #endif
  7.  
  8. #ifdef HAVE_UNISTD_H
  9. #include <unistd.h>
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. int main(int argc,char *argv[])
  16. {
  17.   long j;
  18.   int i,r;
  19.   int ch;
  20.   FILE *si, *so;
  21.   
  22.   if(argc>2) {
  23.     fprintf(stderr, "%s: Usage %s [number]\n", argv[0], argv[0]);
  24.     exit(1);
  25.   }
  26.  
  27.   r=atoi(argv[1]);
  28.  
  29. #ifdef AMIGA
  30.   si = stdin;
  31.   so = stdout;
  32. #else
  33.   si = fdopen(fileno(stdin), "rb");
  34.   so = fdopen(fileno(stdout), "wb");
  35. #endif
  36.  
  37.   if(fseek(si, 0L, SEEK_END))
  38.     perror(argv[0]);
  39.   for(j=ftell(si)/r-1; j>=0; j--) {
  40.     if(fseek(si, j*r, SEEK_SET))
  41.       perror(argv[0]);
  42.     for(i=0; i<r; i++) {
  43.       ch=fgetc(si);
  44.       fputc(ch, so);
  45.     }
  46.   }
  47.   
  48.   return(0);
  49. }
  50.